﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace Client.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult ThirdPartyLogin()
        {

            ViewBag.url = "http://localhost:63840/Authentication/Login";
            ViewBag.callbackUrl = HttpUtility.UrlEncode("http://localhost:63837/Home/CheckThirdPartyLoginState");
            ViewBag.clientId = "clientid";
            ViewBag.jumpUrl = HttpUtility.UrlEncode("https://www.baidu.com");
            return View();
        }

        public ActionResult CheckThirdPartyLoginState(string token, string jumpurl)
        {
            var checkapi = string.Format("{0}?token={1}", "http://localhost:63840/Authentication/CheckAndGetUserInfo", token);
            WebClient webClient = new WebClient();
            webClient.Encoding = Encoding.UTF8;
            var response = webClient.DownloadString(checkapi);
            if (response.Contains("1"))
                return Json(new { code = 0, msg = "验证成功！", jumpurl= jumpurl,data=response }, JsonRequestBehavior.AllowGet);
            else return Json(new { code = 0, msg = "验证失败！" }, JsonRequestBehavior.AllowGet);
        }
    }
}